package com.sparrow.event.invoke.impl;

import com.sparrow.common.event.IEventInvoker;
import java.lang.reflect.Method;

/**
 * 基于反射的事件执行器
 */
public class ReflectEventInvoker implements IEventInvoker {

    private final Object object;
    private final Method method;

    public ReflectEventInvoker(Object object, Method method) {
        this.object = object;
        this.method = method;
    }

    @Override
    public void invoke(Object[] args) {
        try {
            method.invoke(object, args);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public Method getMethod() {
        return method;
    }

}
